package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.controller.vo.RegisterVo;
import com.example.demo.entity.Admin;
import com.example.demo.entity.Circle;
import com.example.demo.entity.User;
import com.example.demo.sevice.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**·
 * 管理员接口控制类
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    AdminService adminService;
    //登陆接口
    @PostMapping("login")
    public ReturnData login(@RequestBody Admin admin) {
        return  adminService.login(admin.getUsername(),admin.getPassword());
    }

    /**
     * 分页获取用户列表接口
     * @param page 页码
     * @param limit  每一页的长度 默认为20
     * @return
     */
    @GetMapping("/user/list")
    public ReturnData list(@RequestParam(defaultValue = "1")int page,
                           @RequestParam(defaultValue = "20") int limit,
                           @RequestParam(defaultValue = "") String nickname) {
        return  adminService.getUserList(page,limit,nickname);
    }

    /**
     * 删除用户的接口
     * @return
     */
    @PostMapping("/user/delete")
    public ReturnData deleteUser(@RequestBody User user) {
        return  adminService.deleteUser(user.getId());
    }

    /**
     * 更新用户信息
     * 新增用户，当新增用户的时候，提交的ID为0
     * @param user 用来接收需要更新的字段
     * @return
     * @throws InterruptedException
     */
    @PostMapping("updateUserInfo")
    public ReturnData updateUserInfo(@RequestBody RegisterVo user)  {

        return  adminService.updateUserInfo(user);
    }

    /**
     * 圈子列表接口 面向管理员的
     * @param page 页码
     * @param pageSize  每一页的长度 默认为10
     * @return
     */
    @GetMapping("/circle/list")
    public ReturnData getCircleList(@RequestParam(defaultValue = "1")int page,
                           @RequestParam(defaultValue = "20") int pageSize) {
        return  adminService.getCircleList(page,pageSize);
    }

    //
    /**
     * 删除圈子的接口
     * @return
     */
    @PostMapping("/circle/delete")
    public ReturnData deleteCircle(@RequestBody Circle circle) {
        return  adminService.deleteCircle(circle.getId());
    }

    @GetMapping("/comment/list")
    public ReturnData getCommentLit(@RequestParam(defaultValue = "1")int page,
                                    @RequestParam(defaultValue = "10") int pageSize,
                                    int circleId){
        return adminService.getCommentList(page,pageSize,circleId);
    }
}
